package com.ecs.core.map;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.Gdx;
import com.ecs.core.utils.JsonRegion;
import com.badlogic.gdx.graphics.Color;

public class TreeData{

	public int blockId = -1;
	public int terrainId = -1;//可生成地形id
	public int treeId = -1;
	// 纹理区域
    public transient TextureRegion grow;//常规图
	public transient TextureRegion deadman;//砍伐后的木桩图
    public transient Color color;//小地图颜色
	public String colorPath = "";
	
	public JsonRegion growData;
	public JsonRegion deadmanData;
	/**
     * 从JSON文件加载地形数据
     * @param assetManager 资源管理器
     * @param path JSON文件路径
     * @return 加载完成的地形数据
     */
    public static TreeData loadFromJson(AssetManager assetManager, String path) {
        Json json = new Json();
        TreeData data = json.fromJson(TreeData.class, Gdx.files.internal(path));
		
		data.grow = JsonRegion.CreateRegion(data.growData,assetManager);
		data.deadman = JsonRegion.CreateRegion(data.deadmanData,assetManager);
		
		if(data.colorPath.equals("")){
			data.color = Color.WHITE;
		}else{
			data.color = json.fromJson(Color.class,Gdx.files.internal(data.colorPath));
		}
        return data;
    }

    /**
     * 检查当前环境参数是否匹配此树木
     * @param terrainId 当前树木可生成的对应地形
     * @return 是否匹配
     */
    public boolean matchesEnvironment(int terrainId) {
        return this.terrainId == terrainId;
    }
}
